home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / patches / crssd603.lha / Patcher < prev    next >
Text File  |  1995-10-17  |  9KB  |  316 lines

  1. ;Script to apply patches
  2. ;$VER: Patcher 6.01 (17.10.95)
  3. ;Copyright © 1992-1994 CONSULTRON.  All rights reserved
  4. ; Use of this script in commercial products is expressly forbidden without
  5. ; written permission.
  6. ;
  7. ; The program spatch is provided by SAS Institute.  They retain all copyrights
  8. ; to that program.  It is available for commercial distribution only to those
  9. ; users who have purchased their SAS C Compiler and are registered with them.
  10.  
  11. ;***************************************************************************
  12.  
  13. ;Copy a new file to the product disk
  14. ;Input: newfile (path and name of new file)
  15.  
  16. (procedure copynew
  17.     (    (if (not PatchOnly)
  18.             (    (if (getsize ("%ld/%s" wversion newfile) )
  19.                     (    (if (not DeleteOnly)
  20.                             (    (copyfiles
  21.                                     (source ("%ld/%s" wversion newfile) )
  22.                                     (dest (pathonly ("%s%s" prod newfile) ) )
  23.                                 )
  24.                             )
  25.                         )
  26.                     )
  27.                     (    (delete ("%s%s" prod newfile) ) )
  28.                 )
  29. ;                (if    (> wversion currentver )
  30. ;                    (set currentver wversion)
  31. ;                )
  32.             )
  33.         )
  34.     )
  35. )
  36.  
  37. ;***************************************************************************
  38.  
  39. ;Perform an spatch
  40. ;Input: file (path and file to patch)
  41.  
  42. (procedure patch
  43.     (    (if (and (not DeleteOnly) (not CopyOnly) )
  44.             (    (set patchfile ("%ld/%s" wversion file) )
  45.                 (set prodfile ("%s%s" prod file) )
  46.                 (set prodfile (substr prodfile 0 (- (strlen prodfile) 1 ) ) )
  47.                 (set tempdir "ram:")
  48.                 (set temp ("%s%s" tempdir (fileonly prodfile)))
  49.                 (if    (= 0 (run ("%s -o%s -p%s %s" spatch temp patchfile prodfile) ))
  50. ;                    (if    (> wversion currentver )
  51. ;                        (set currentver wversion)
  52. ;                    )
  53.                 )
  54.                 ;Replace original file with temp file
  55.                 (if (> (getsize temp) 10 )
  56.                     (    ;Clone protection bits
  57.                         (protect temp (protect patchfile) )
  58.                         (copyfiles
  59.                             (source temp)
  60.                             (dest (pathonly prodfile) )
  61.                             (newname (fileonly prodfile) )
  62.                         )
  63.                     )
  64.                 )
  65.                 ;Delete temporary file
  66.                 (delete temp)
  67.             )
  68.         )
  69.     )
  70. )
  71.  
  72.  
  73. ;Apply the spatch stuff
  74. ;Set DeleteOnly for delete phase
  75.  
  76. ;**************************************************************************
  77. (procedure DoPatch
  78.     (    (while (exists ("%ld" wversion) (noreq) )
  79.             (    (foreach ("%ld" wversion) "#?"
  80.                     (    ;(debug @each-name)
  81.                         (if (< @each-type 0)    ;check for file
  82.                             (    (if (= "@" (substr @each-name (- (strlen @each-name) 1 )))
  83.                                     (    ;Apply patches with spatch
  84.                                         (set file @each-name)
  85.                                         (patch)
  86.                                     )
  87.                                     (    ;Copy the file directly
  88.                                         (set newfile @each-name)
  89.                                         (copynew)
  90.                                     )
  91.                                 )
  92.                             )
  93.                             (    ;@each-name is a directory
  94.                                 (set dir @each-name)
  95.                                 (foreach ("%ld/%s" wversion dir) "#?"
  96.                                     (    (if (< @each-type 0)    ;check for file
  97.                                             (    (if (= "@" (substr @each-name (- (strlen @each-name) 1 )))
  98.                                                     (    ;Apply patches with spatch
  99.                                                         (set file (tackon dir @each-name))
  100.                                                         (patch)
  101.                                                     )
  102.                                                     (    ;Copy the file directly
  103.                                                         (set newfile (tackon dir @each-name))
  104.                                                         (copynew)
  105.                                                     )
  106.                                                 )
  107.                                             )
  108.                                             (    ;@each-name is a directory
  109.                                                 (set dir2 (tackon dir @each-name))
  110.                                                 (foreach ("%ld/%s" wversion dir2) "#?"
  111.                                                     (    (if (< @each-type 0)    ;check for file 
  112.                                                             (    (if (= "@" (substr @each-name (- (strlen @each-name) 1)))
  113.                                                                     (    ;Apply patches with spatch
  114.                                                                         (set file (tackon dir2 @each-name))
  115.                                                                         (patch)
  116.                                                                     )
  117.                                                                     (    ;Copy the file directly
  118.                                                                         (set newfile (tackon dir2 @each-name))
  119.                                                                         (copynew)
  120.                                                                     )
  121.                                                                 )
  122.                                                             )
  123.                                                         )
  124.                                                     )
  125.                                                 )
  126.                                             )
  127.                                         )
  128.                                     )
  129.                                 )
  130.                             )
  131.                         )
  132.                     )
  133.                 )
  134.  
  135.                 (set wversion (+ wversion 1) )
  136.             )
  137.         )
  138.     )
  139. )
  140.  
  141.  
  142. ;***************************************************************************
  143. ;Preserve CIN
  144. (procedure preserveCIN
  145. ; Save the CIN to a CIN file on the disk
  146.     (run ("serfile %s >%s" (tackon prod "READ.ME") (tackon prod "CIN")))
  147. ; set the CIN temporarily to XXXX-YYYY
  148.     (run ("serfile %s CIN: %s" (tackon prod "READ.ME") "XXXX-YYYY"))
  149.     (set CINsaved 1)
  150. )
  151.  
  152. ;***************************************************************************
  153. ;Restore Old State
  154. (procedure restoreCIN
  155. ;restore product assignment
  156.     (if    (= newassign 1)
  157.         (    (makeassign ("%s" prodname) ("C%s:" prodname))
  158.             (makeassign ("C%s" prodname))
  159.         )
  160.     )
  161. ; reset the CIN back to the customer's CIN
  162.     (if (= CINsaved 1)
  163.         (run ("serfile %s CIN: `type %s`" (tackon prod "READ.ME") (tackon prod "CIN")))
  164.     )
  165. )
  166.  
  167. ;***************************************************************************
  168. ; Get the version number from a file
  169. (procedure getVersion_File
  170.     (set version (getversion verfile))
  171.     (if (= 0 version)
  172.         (set version defver)
  173.         (    (set ver (/ version 65536))
  174. (debug version)
  175.             (set version ("%ld" (+ (* 100 ver) (- version (* ver 65536)))) )
  176. (debug version)
  177.         )
  178.     )
  179. )
  180.  
  181.  
  182. ;***************************************************************************
  183. ;***************************** MAIN ****************************************
  184. ;***************************************************************************
  185.  
  186. ;This can be replaced by checks for "copy of <product>" etc.
  187. (set prodname "CrossDOS")
  188. (set prod ("%s:" prodname))
  189. (set defverbeg "600")
  190. (set defverend "602")
  191.  
  192.  
  193. ;Starting version number
  194. (set verfile (tackon prod "Read.ME"))
  195. (set defver defverbeg)
  196. (getVersion_File)    ; return in 'version"
  197. (set startversion version)
  198.  
  199. ;(exit (quiet))
  200.  
  201. (set @abort-button "Abort Update")
  202. (onerror (restoreCIN) )
  203.  
  204. ;Check if the <product>: being referenced is the assignment or the disk
  205. (askdisk 
  206.     (prompt ("Please insert %s in any drive" prod))
  207.     (help "To update, you must use a copy of the latest release of "
  208.             ("the %s product disk you have.  " prodname)
  209.             ("In addition, the volume MUST BE named `%s'.  " prodname)
  210.             ("If the disk you have is labeled `Copy_of_%s', " prodname)
  211.             "relabel it using the Workbench menu selection `Icons/Rename...'." )
  212.     (dest ("%s" prodname))
  213. )
  214.  
  215. (if (<> prod (expandpath prod))
  216.     (    (makeassign ("C%s" prodname) prod)    ;temp reassign product assignment
  217.         (set newassign 1)
  218.         (makeassign prodname)        ;clear the product assignment
  219.     )
  220. )
  221.  
  222. ;Force user level to 1 or 2. This is unfortuntely required because otherwise
  223. ;we can't present a menu of choices to the user.
  224. (if (= @user-level 0) 
  225.     (
  226.         (user 1)
  227.         (set @user-level 0)
  228.     )
  229. )
  230.  
  231. ; Test to see if the first patch directory exists.  If not, it may be that the
  232. ; archive was not unarc'd with full path names preserved.
  233. (if (not (= 2 (exists  startversion  (noreq) ) ) )
  234.     (    (message "Could not find directory '" startversion "'.  Make sure you unarc "
  235.             "the archive with the option to preserve directories.\n"
  236.             "[Example: LHA x -x <archivename>]\n"
  237.             "OR\n"
  238.             "This archive of patch files does not update the release "
  239.             "you currently have."
  240.         )
  241.         (exit (quiet))
  242.     )
  243. )
  244.  
  245. (set currentver startversion)
  246.  
  247. ; Put diag/spatch into ram:.  Since this program is to be used quite frequently
  248. (set spatch "ram:SPatch")
  249. (set spatchsrc (tackon prod "diag/SPatch"))
  250. (if (exists "SPatch" (noreq) )    ; a new SPatch exists in the current directory. Use it instead
  251.     (    (delete (tackon prod "diag/lpatch"))    ;delete the old lpatch
  252.         (copyfiles (source "SPatch") (dest (pathonly spatchsrc)))
  253.     )
  254. )
  255. (copyfiles (source spatchsrc) (dest (pathonly spatch) ) )
  256.  
  257.  
  258. (preserveCIN)
  259.  
  260. (set wversion "S")
  261.  
  262. ;Delete phase
  263. (set wversion (+ 1 startversion))
  264. (set DeleteOnly 1)
  265. (set PatchOnly 0)
  266. (set CopyOnly 0)
  267. (DoPatch)
  268.  
  269. ;Patch phase
  270. (set wversion (+ 1 startversion))
  271. (set DeleteOnly 0)
  272. (set PatchOnly 1)
  273. (set CopyOnly 0)
  274. (DoPatch)
  275.  
  276. ;Copy phase
  277. (set wversion (+ 1 startversion))
  278. (set DeleteOnly 0)
  279. (set PatchOnly 0)
  280. (set CopyOnly 1)
  281. (DoPatch)
  282.  
  283. (set wversion (+ -1 wversion))
  284.  
  285. (set verfile (tackon prod "Read.ME"))
  286. (set defver defverend)
  287. (getVersion_File)    ; return in 'version'
  288. (set currentver version)
  289.  
  290. (set wversion ("%ld" wversion))
  291.  
  292. (if    (= startversion wversion)
  293.     (    (message ("Your %s disk is already at release %s.%s" prodname (substr wversion 0 1) (substr wversion 1)))
  294.     )
  295.     (if    (> startversion wversion)
  296.         (    (message ("Your %s disk is already updated past the releases in this archive" prodname))
  297.         )
  298.         (if    (< currentver wversion)
  299.             (    (message ("Your %s disk COULD NOT be updated to release %s.%s\n" prodname (substr wversion 0 1) (substr wversion 1))
  300.                         ("It appears to be at release %s.%s\n" (substr currentver 0 1) (substr currentver 1))
  301.                         ("Make sure you patch a GOOD copy of the %s product disk ONLY!" prodname)
  302.                 )
  303.             )
  304.             (if    (= currentver wversion)
  305.                 (    (message ("Your %s disk has been updated to release %s.%s" prodname (substr currentver 0 1) (substr currentver 1))
  306.                     )
  307.                 )
  308.             )
  309.         )
  310.     )
  311. )
  312.  
  313. (restoreCIN)
  314.  
  315. (exit (quiet))
  316.